package com.js.comment.controller;

import com.js.comment.entity.Comment;
import com.js.comment.mapper.CommentMapper;
import com.js.comment.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/selectAll")
    @ResponseBody
    public List<Comment> selectAllArticleComment(){
        List<Comment> list = commentService.selectAllArticleComment();
        return list;
    }

    @PostMapping("/saveComment")
    @ResponseBody
    public boolean saveComment(Comment comment){
        commentService.saveComment(comment);
        return true;
    }
    @ResponseBody
    @DeleteMapping("/deleteComment")
    public boolean deleteComment(String id){
        commentService.deleteCommentById(id);
        return true;
    }

    @GetMapping("/selectById")
    public List<Comment> selectById(String id){
        List<Comment> list = commentService.selectById(id);
        return list;
    }

    @GetMapping("/likenumThumbup")
    public String updateCommentLikenumThumbup(String id){
        commentService.updateCommentLikenumThumbup(id);
        return "comment-list";
    }

    @GetMapping("/selectAllCommentId")
    @ResponseBody
    public List<Comment> selectAllCommentId(String parentid){
        List<Comment> list = commentService.selectAllCommentId(parentid);
        return list;
    }
}
